package com.agile.leetcode.jdk8.functionintereface;

/**
 * @Author KD
 * @Date 2021/1/27 15:41
 */
public class FunctionInterfaceDemo {
    public static void main(String[] args) {
        // 调用自定义函数式接口
        consumer((str) -> {
            System.out.println(str);
        }, "name");
        bigConsumer((str) -> Integer.parseInt(str), "5");
        accept((num) -> num + "", 5);
        suppier(() -> "czk，你好");
    }

    /**
     * @param consumer
     * @param str
     */
    public static void consumer(MyConsumer<String> consumer, String str) {
        consumer.consume(str);
    }

    /**
     * @param myBigConsumer
     * @param str
     */
    public static void bigConsumer(MyBigConsumer<String> myBigConsumer, String str) {
        System.out.println(myBigConsumer.bigConsumer(str));
    }

    /**
     * @param function
     * @param num
     */
    public static void accept(MyFunction<Integer, String> function, Integer num) {
        String accept = function.accept(num);
        System.out.println(accept);
    }

    public static void suppier(MySuppier<String> suppier) {
        String suppler = suppier.suppler();
        System.out.println(suppler);
    }
}

@FunctionalInterface
interface MyConsumer<T> {
    void consume(T t);
}

@FunctionalInterface
interface MyBigConsumer<T> {
    Integer bigConsumer(T t);
}

@FunctionalInterface
interface MyFunction<T, V> {
    V accept(T t);
}

@FunctionalInterface
interface MySuppier<T> {
    T suppler();
}
